package top.codecrab.countDown;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author codecrab
 * @since 2021年06月30日 18:25
 */
public class CountDownDemo {
    /**
     * 解决
     */
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                count.countDown();
                System.out.println(Thread.currentThread().getName() + "\t被灭");
            }, CountryEnum.forEachFindMessage(i)).start();
        }

        count.await();
        System.out.println("秦国统一");
    }


    /**
     * 普通倒计时，线程还没有全部结束，main的任务就结束了
     */
    public static void test() {
        AtomicInteger count = new AtomicInteger(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                count.getAndDecrement();
                System.out.println(Thread.currentThread().getName() + "\t号同学走了");
            }, String.valueOf(i)).start();
        }

        System.out.println("锁门");
    }
}
